#include <stdio.h>
#include <string.h>

/* utf-8 */
#define UTF_V        "\342\224\202"         /* U+2502, Vertical line drawing char */
#define UTF_VR        "\342\224\234"        /* U+251C, Vertical and right */
#define UTF_H        "\342\224\200"         /* U+2500, Horizontal */
#define UTF_UR        "\342\224\224"        /* U+2514, Up and right */
#define UTF_HD        "\342\224\254"        /* U+252C, Horizontal and down */

#define VT_BEG        "\033(0\017"        /* use graphic chars */
#define VT_END        "\033(B"            /* back to normal char set */
#define VT_V        "x"                   /* see UTF definitions above */
#define VT_VR        "t"
#define VT_H        "q"
#define VT_UR        "m"
#define        VT_HD        "w"

static struct {
    const char *empty_2;        /*    */
    const char *branch_2;        /* |- */
    const char *vert_2;                /* |  */
    const char *last_2;                /* `- */
    const char *single_3;        /* --- */
    const char *first_3;        /* -+- */
}   sym_ascii = {
        "  ", "|-", "| ", "`-", "---", "-+-"}, 
    sym_utf = {
        "  ",
        UTF_VR UTF_H,
        UTF_V " ",
        UTF_UR UTF_H, UTF_H UTF_H UTF_H, UTF_H UTF_HD UTF_H}, 
    sym_vt100 = {
        "  ",
        VT_BEG VT_VR VT_H VT_END,
        VT_BEG VT_V VT_END " ",
        VT_BEG VT_UR VT_H VT_END,
        VT_BEG VT_H VT_H VT_H VT_END, VT_BEG VT_H VT_HD VT_H VT_END},
    *sym = &sym_ascii;


void escape(void)
{
    printf("%s:\n", UTF_V);         // │
    printf("%s:\n", UTF_VR);        // ├
    printf("%s:\n", UTF_H);         // ─
    printf("%s:\n", UTF_UR);        // └
    printf("%s:\n", UTF_HD);        // ┬
    printf("%s:\n", VT_BEG);        // 
    printf("%s:\n", VT_END);        // 
    printf("%s:\n", VT_V);          // x
}

void pstree(void)
{
    char *e1 = "P\271\004\bS\271\004\b]\271\004\bg\271\004\bq\271\004\b|\271\004\bP\271\004\b\207\271\004\b\216\271\004\b\223\271\004\b\232\271\004\b\244\271\004\bP\271\004\b\256\271\004\b\261\271\004\b\264\271\004\b\267\271\004\b\273\271\004\b";
    char *e2 = "P\271\004\b\256\271\004\b\261\271\004\b\264\271\004\b\267\271\004\b\273\271\004\b";
    char *e3 = "P\271\004\b\207\271\004\b\216\271\004\b\223\271\004\b\232\271\004\b\244\271\004\bP\271\004\b\256\271\004\b\261\271\004\b\264\271\004\b\267\271\004\b\273\271\004\b";
    char *e4 = "\267";

    //printf("[%s]\n[%s]\n[%s]\n", e1, e2, e3);

    printf("[%s]\n", e4);
}

int main()
{
    char a = '\61';   // 字符1
    char b = '\141';  // 字符a
    char c = '\x31';  // 字符1
    char d = '\x61';  // 字符a
    char *e = "\61\141";

    #if 1
    char *str1 = "\x31\x32\x33\x61\x62\x63";                // 字符串"123abc"
    char *str2 = "\61\62\63\141\142\143";                   // 字符串"123abc"
    char *str3 = "The string is: \61\62\63\x61\x62\x63";    // 混用八进制和十六进制形式

    printf("%ld\n", strlen("abc"));         // 3

	printf("%ld\n", strlen("t\328\t"));     // 4， \t、\32被解释为转义字符，算一个字符
    printf("%s\n", "t\328\t\61");           // "t8      1" ,  \32为空
    printf("%s\n", "t\3289\t\61");          // "t89      1" , \32为空
    #endif
    
    #if 0
    printf("%c %c %c %c\n", a, b, c, d);    // 1 a 1 a
    printf("%ld\n", strlen(e));             // 2

    printf("[%s] [%s] [%s]\n", str1, str2, str3); // [123abc] [123abc] [The string is: 123abc]
    printf("%ld\n", strlen(str1));          // 6
    #endif

    // escape();
    pstree();

	return 0;
}

